<template>
  <div>
    <cus-modal ref="modal" width="450" title="编辑单位名称" @onOk="onOk">
      <Form ref="menuFormValidate" :model="menuFormData" :rules="formValidate" :label-width="120">
        <FormItem label="单位名称" prop="unitName">
          <Input clearable maxlength="20" v-model="menuFormData.unitName"></Input>
        </FormItem>
        <Spin size="large" fix v-if="modelLoading"></Spin>
      </Form>
    </cus-modal>
  </div>
</template>
  
<script>
import { editUnit, } from "@/api/organ/organization";
export default {
  data() {
    return {
      modelLoading: false,
      menuFormData: {},
      formValidate: {
        unitName: [
          { required: true, message: "单位名称必填!", trigger: "change,blur" },
        ],
      },
    };
  },
  methods: {
    show(row) {
      console.log(row);
      this.menuFormData = row;
      this.$refs["modal"].show = true;
    },
    // 提交修改单位名称
    onOk() {
      this.$refs['menuFormValidate'].validate((valid) => {
        if (valid) {
          this.modelLoading = true;
          let params = {
            unitCode: this.menuFormData.unitCode,
            unitName: this.menuFormData.unitName,
          };
          editUnit(params).then((res) => {
            this.modelLoading = false;
            if (res.code == 1) {
              this.$Message.success("编辑成功");
              this.$refs.modal.show = false;
              this.$parent.onInit();
            }
          });
        }
      });
    },
  },
};
</script>
  
<style scoped lang="scss"></style>
  